var nodeData = function (view, node) {
    Ext.Ajax.request({
        url: 'structure/getElement',
        params: {
            node: node.get('id')
        },
        success: function (response) {
            var element = Ext.decode(response.responseText);
            if (element.type == 'employee') {
                var generalInfoHeader = 'Основные сведения';
                var advancedInfoHeader = 'Дополнительные сведения';
                var employeeId = element.id;
                var employeeLname = element.lname;
                var employeeFname = element.fname;
                var employeePname = element.pname;
                var employeeEmail = element.email;
                var employeeBirthDate = element.birthDate;
                var employeeJobPosition = element.jobPosition;
            } else {
                var nodeName = element.name;
                var nodeDescription = element.description;
                var dataPanelHeader;
                if (element.type == 'root')
                    dataPanelHeader = 'Компания: ' + nodeName;
                else if (element.type == 'division')
                    dataPanelHeader = 'Подразделение: ' + nodeName;
                else if (element.type == 'project')
                    dataPanelHeader = 'Проект: ' + nodeName;
            }

            if (element.type == 'employee') {

                var employeeIdField = Ext.create('Ext.form.TextField', {
                    xtype: 'textfield',
                    id: 'employeeIdField',
                    fieldLabel: 'ID',
                    value: employeeId,
                    anchor: '100%',
                    readOnly: true
                });

                var employeeLnameField = Ext.create('Ext.form.TextField', {
                    xtype: 'textfield',
                    id: 'employeeLnameField',
                    fieldLabel: 'Фамилия',
                    value: employeeLname,
                    anchor: '100%',
                    readOnly: true
                });

                var employeeFnameField = Ext.create('Ext.form.TextField', {
                    xtype: 'textfield',
                    id: 'employeeFnameField',
                    fieldLabel: 'Имя',
                    value: employeeFname,
                    anchor: '100%',
                    readOnly: true
                });

                var employeePnameField = Ext.create('Ext.form.TextField', {
                    xtype: 'textfield',
                    id: 'employeePnameField',
                    fieldLabel: 'Отчество',
                    value: employeePname,
                    anchor: '100%',
                    readOnly: true
                });

                var employeeEmailField = Ext.create('Ext.form.TextField', {
                    xtype: 'textfield',
                    id: 'employeeEmailField',
                    fieldLabel: 'Эл. почта',
                    value: employeeEmail,
                    anchor: '100%',
                    readOnly: true
                });

                var employeeBirthDateField = Ext.create('Ext.form.DateField', {
                    xtype: 'Datefield',
                    id: 'employeeBirthDateField',
                    fieldLabel: 'Дата рождения',
                    format: 'd.m.Y',
                    value: new Date(employeeBirthDate),
                    anchor: '100%',
                    readOnly: true
                });

                var employeeJobPositionField = Ext.create('Ext.form.TextField', {
                    xtype: 'textfield',
                    id: 'employeeJobPositionField',
                    fieldLabel: 'Должность',
                    value: employeeJobPosition,
                    anchor: '100%',
                    readOnly: true
                });

                var generalInfo = [
                    employeeIdField,
                    employeeLnameField,
                    employeeFnameField,
                    employeePnameField,
                    employeeJobPositionField
                ];

                var advancedInfo = [
                    employeeBirthDateField,
                    employeeEmailField
                ];

                var employeeGeneralInfoPanel = Ext.create('Ext.FormPanel', {
                    id: 'employeeGeneralInfoPanel',
                    labelWidth: 100,
                    frame: true,
                    title: generalInfoHeader,
                    bodyStyle: 'padding:5px 5px 0',
                    width: 450,
                    defaults: {width: 300},
                    defaultType: 'textfield',
                    items: generalInfo
                });

                var employeeAdvancedInfoPanel = Ext.create('Ext.FormPanel', {
                    id: 'employeeAdvancedInfoPanel',
                    labelWidth: 100,
                    frame: true,
                    title: advancedInfoHeader,
                    bodyStyle: 'padding:5px 5px 0',
                    width: 450,
                    defaults: {width: 300},
                    defaultType: 'textfield',
                    items: advancedInfo
                });

                var employeeInfoPanel = Ext.create('Ext.TabPanel', {
                    id: 'employeeInfoPanel',
                    activeTab: 0,
                    frame: true,
                    items: [
                        employeeGeneralInfoPanel,
                        employeeAdvancedInfoPanel
                    ]
                });

            } else {

                var nodeNameField = Ext.create('Ext.form.TextField', {
                    xtype: 'textfield',
                    id: 'nodeNameField',
                    fieldLabel: 'Название',
                    value: nodeName,
                    anchor: '100%',
                    readOnly: true
                });

                var nodeDescriptionField = Ext.create('Ext.form.TextArea', {
                    xtype: 'textarea',
                    id: 'nodeDescriptionField',
                    fieldLabel: 'Описание',
                    value: nodeDescription,
                    anchor: '100%',
                    readOnly: true
                });

                var nodeInfo = [
                    nodeNameField,
                    nodeDescriptionField
                ];

                var nodeInfoPanel = new Ext.FormPanel({
                    id: 'nodeInfoPanel',
                    labelWidth: 100,
                    frame: true,
                    title: dataPanelHeader,
                    bodyStyle: 'padding:5px 5px 0',
                    width: 450,
                    defaults: {width: 300},
                    defaultType: 'textfield',
                    items: nodeInfo
                });
            }

            var infoPane = Ext.getCmp('infoPanel');

            if (element.type == 'employee') {
                infoPane.removeAll();
                infoPane.add(employeeInfoPanel);
            } else {
                infoPane.removeAll();
                infoPane.add(nodeInfoPanel);
            }

            infoPane.doLayout();
        },
        failure: function () {
            Ext.Msg.alert('Ошибка подключения к серверу');
        }
    })
};